package com.chuxi.demo;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @ Author:任留辉
 * @ Description:
 * @ Date:Created in 18:30 2021/7/23 0023
 */
public class JDKProxy implements InvocationHandler {
    /** 需要代理的目标对象 */
    private Object targetObject;

    /**
     * 将目标对象传入进行代理
     */
    public JDKProxy(Object targetObject) {
        this.targetObject = targetObject;
    }

    /**
     * invoke方法
     */
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("钱");
        //方法的返回值
        Integer res = (Integer) method.invoke(targetObject, args);
        res+=10;
        System.out.println("后");
        return res;
    }

}
